package com.zhuss.${moudle}.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.${moudle}.${poEntityLower}.Stop${poEntity}Bo;
import com.zhuss.bean.vo.${moudle}.${poEntityLower}.Detail${poEntity}Vo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.${moudle}.db.dao.ext.${poEntity}Dao;
import com.zhuss.${moudle}.db.entity.${poEntity};
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.util.JsonUtil;

/**
 * 创建${tableComment} processor
 * @Author: zhushanshuo
 * @Date: ${creatTime}
 */
@Component("${poEntityLower}Stop")
public class ${poEntity}Stop extends AbstractProcessor<Object, Stop${poEntity}Bo> implements Processor<Object, Stop${poEntity}Bo> {

    @Autowired
    private ${poEntity}Dao ${poEntityLower}Dao;
    
    @Autowired
	@Qualifier("${poEntityLower}Read")
	private ${poEntity}Read ${poEntityLower}Read;
    
    @Autowired
    private ${poEntity}Check ${poEntityLower}Check;
    
    /**
     * 校验
     */
    @Override
    public void check(Stop${poEntity}Bo bo) throws DzcxException {
    	// 当前${tableComment}不满足停用条件
		if (!${poEntityLower}Check.checkStop(bo.get${poEntity}Id())) {
			throw new DzcxException(ExceptionCode.当前${tableComment}不满足停用条件);
		}
    }
    
    /**
     * 操作方法
     * @throws DzcxException 
     */
    @Override
    public Object process(Stop${poEntity}Bo param) throws DzcxException {
    	
    	Long ${poEntityLower}Id = param.get${poEntity}Id();
    	
    	${poEntity} record = new ${poEntity}();
    	record.set${poEntity}Id(param.get${poEntity}Id());
    	record.setStatus(param.getStatus());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	${poEntityLower}Dao.updateByPrimaryKeySelective(record);
    	
    	String name = ((Detail${poEntity}Vo) ${poEntityLower}Read.detail(${poEntityLower}Id)).getName();
    	
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(Stop${poEntity}Bo param) throws DzcxException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.默认模块请修改.key());
    	record.setAction(LogActionEnum.${tableComment}停用.key());
    	record.setTargetId(param.get${poEntity}Id());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
